#include <stdio.h>
#include <stdlib.h>
#include <sched.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <wait.h>
#include <unistd.h>
#include <signal.h>
typedef void (*sighandler_t) (int);
int pid;
void add(){
	if(pid!=0)	//如果是父进程
		setpriority(PRIO_PROCESS,getpid(),(getpriority(PRIO_PROCESS,getpid())+1));//优先级加一
}
void minus(){
	if(pid==0)	//如果是子进程
		setpriority(PRIO_PROCESS,getpid(),(getpriority(PRIO_PROCESS,getpid())-1));//优先级减一

}
int main()
{
	signal(SIGINT,(sighandler_t)add);
	signal(SIGTSTP,(sighandler_t)minus);
	if((pid=fork())>0)	//如果是父进程
	{
		for(int i=0;i<10;i++){
			//打印十次，每次间隔1s
			sleep(1);
			printf("I'm father,my pid id %d,my priority is %d,my scheduler is %d\n",getpid(),getpriority(PRIO_PROCESS,getpid()),sched_getscheduler(getpid()));
			sleep(1);
		}
	}else{
		for(int i=0;i<10;i++){
			sleep(1);
			printf("I'm son,my pid is %d,my priority is %d,my scheduler is %d\n",getpid(),getpriority(PRIO_PROCESS,getpid()),sched_getscheduler(getpid()));
			sleep(1);
		}
	}
	return EXIT_SUCCESS;	
}
